const models = require('../db')
const express = require('express')
const router = express.Router()
const mysql = require('mysql')
const $sql = require('../sqlMap')
// 连接数据库
// const conn = mysql.createConnection(models.mysql)
const conn = mysql.createConnection(models.mysql_config)
// const conn = mysql.createConnection(models.handleDisconnection)
// const conn = models.handleDisconnection
// handleDisconnection()
// conn.connect()

const jsonWrite = function (res, ret) {
    if (typeof ret === 'undefined') {
        res.json({
            code: '1',
            msg: '操作失败'
        })
    } else {
        res.json({
            "code": '200',
            "msg": 'ok'
        })
    }
}
const jsonWriteShow = function (res, ret) {
    if (typeof ret === 'undefined') {
        res.json({
            code: '1',
            msg: '操作失败'
        })
    } else {
        res.json({
                code: '200',
                msg: 'ok',
                data:{
                    a:10,
                    b:20,
                    c:[1,2,34],
                    ret
                },
                
            }

        )
    }
}


// 接口：查詢信息
router.get('/showUser', (req, res) => {
    const sql = $sql.User.show
    const params = req.query
    console.log('查询', params)
   
        conn.query(sql, [params.cs_id], function (err, result) {
            if (err) {
                console.log(err)
            }
            if (result) {
                jsonWriteShow(res, result)
            }
        })
        conn.close;
})






module.exports = router